//
//  YYGShareView.m
//  YiYuanGou
//
//  Created by 同乐 on 2017/4/27.
//  Copyright © 2017年 同乐1234521. All rights reserved.
//

#import "YYGShareView.h"


@implementation YYGShareView

+ (instancetype)sharedInstance {
    static YYGShareView *shareView = nil;
//    static dispatch_once_t onceToken;
//    dispatch_once(&onceToken, ^{
//        shareView = [[NSBundle mainBundle] loadNibNamed:@"YYGShareView" owner:nil options:nil].lastObject;
//    });

    if (!shareView) {
        shareView = (YYGShareView *)[[NSBundle mainBundle] loadNibNamed:@"YYGShareView" owner:nil options:nil].firstObject;
        
    }
    return shareView;
}

- (void)shareViewHidden:(BOOL)hidden {
    __weak typeof(self)weakSelf = self;

    
    if (hidden == YES) {
        
        [UIView animateWithDuration:0.26 animations:^{
            weakSelf.sharePanelHeight.constant = 0;
            [weakSelf layoutIfNeeded];
            
        } completion:^(BOOL finished) {
            [weakSelf removeFromSuperview];
        }];
        
    } else {
        [[UIApplication sharedApplication].keyWindow addSubview:weakSelf];
        
        [UIView animateWithDuration:0.26 animations:^{
            weakSelf.sharePanelHeight.constant = 142;
            [weakSelf layoutIfNeeded];

        } completion:^(BOOL finished) {
            
        }];
    }
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self shareViewHidden:YES];
}

#pragma mark - Event
- (IBAction)wxFriendShare:(id)sender {
    [self shareViewHidden:YES];

    if (self.shareCallback) {
        self.shareCallback(0);
    }
}
- (IBAction)wxLineShare:(id)sender {
    [self shareViewHidden:YES];

    if (self.shareCallback) {
        self.shareCallback(1);
    }
}
- (IBAction)cancelShare:(id)sender {
    [self shareViewHidden:YES];

}


@end
